<template>
  <el-container class="layout-container">
    <el-aside
      class="aside"
      :width="isCollapse ? '64px' : '200px'">
      <!-- logo -->
      <div class="logo" :class="{minLogo : isCollapse}"></div>
      <!-- 导航 -->
       <el-menu
       :collapse= "isCollapse"
        default-active="/"
        class="nav-menu"
        background-color="#002033"
        text-color="#fff"
        active-text-color="#ffd04b"
        router
      >
      <el-menu-item index="/">
        <i class="el-icon-s-home"></i>
        <span slot="title">首页</span>
      </el-menu-item>
      <el-menu-item index="/articles" >
        <i class="el-icon-document"></i>
        <span slot="title">内容管理</span>
      </el-menu-item>
      <el-menu-item index="/image">
        <i class="el-icon-picture"></i>
        <span slot="title">素材管理</span>
      </el-menu-item>
      <el-menu-item index="/add">
        <i class="el-icon-s-promotion"></i>
        <span slot="title">发布文章</span>
      </el-menu-item>
      <el-menu-item index="/comment">
        <i class="el-icon-chat-dot-round"></i>
        <span slot="title">评论管理</span>
      </el-menu-item>
      <el-menu-item index="/fans">
        <i class="el-icon-setting"></i>
        <span slot="title">粉丝管理</span>
        </el-menu-item>
        <el-menu-item index="/settings">
          <i class="el-icon-user"></i>
          <span slot="title">个人设置</span>
        </el-menu-item>
      </el-menu>
      </el-aside>
      <el-container>
        <el-header class="header">
          <div>
          <i :class="isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'" @click="isCollapse = !isCollapse"></i>
          <span>江苏传智播客科技教育有限公司</span>
        </div>
        <el-dropdown>
        <div class="avatar-wrap"><img :src="user.photo" class="avatar"> {{user.name}}<i class="el-icon-arrow-down el-icon--right"></i></div>
        <el-dropdown-menu slot="dropdown">
         <el-dropdown-item>设置</el-dropdown-item>
           <el-dropdown-item @click.native="hQuit">退出</el-dropdown-item>
         </el-dropdown-menu>
          </el-dropdown>
        </el-header>
        <el-main>
          <!-- 嵌套路由出口 -->
       <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: 'Layout',
  data () {
    return {
      isCollapse: false, // 侧边栏状态
      user: {} // 获取的数据
    }
  },
  created () {
    this.loadProfile()
  },
  methods: {
    // 发送axios
    loadProfile () {
      this.$http({
        method: 'GET',
        url: '/mp/v1_0/user/profile'
      }).then(res => {
        // console.log(res)
        this.user = res.data.data // 如果请求成功把信息赋值给user
      }).catch(err => {
        console.log(err)
      })
    },
    hQuit () {
      // 判断是否退出
      this.$confirm('确定退出?').then(() => {
        // 如果确定删除token
        localStorage.removeItem('tokenStr')
        // 再回去登陆页
        this.$router.push('/log')
      }).catch(() => {
      })
    }
  }
}
</script>

<style scoped lang="less">
.layout-container {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}

.aside {
  background-color: #002033;
  .el-menu {
    border-right: none;
  }
  .logo{
      width: 100%;
      height: 60px;
      background: #002244 url(../../img/logo_admin.png) no-repeat center / 140px auto;
    }
    // 覆盖background 的图片和大小，类写在logo的下方。
    .minLogo{
       background-image: url(../../img/logo_admin1.png);
      background-size: 36px auto;
    }
}
.nav-menu {
  .iconfont {
    margin-right: 10px;
    padding-left: 5px;
  }
}
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #ccc;
  .avatar-wrap {
    display: flex;
    align-items: center;
    .avatar {
      width: 30px;
      height: 30px;
      border-radius: 50%;
      margin-right: 10px;
    }
  }
}

.main {
  background-color: #e9eef3;
}
</style>
